<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
 xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	body {
		width: 800px;
	}
	td, th {
		width: 100px;
		text-align: center;
	}
	.pages {
		text-align: right;
	}
	img {
		width: 50px;
		height: 50px;
	}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
	<h2 th:text="#{title}"></h2>
	<div>
		<div>
			<form action="list" >
				账号：<input name="userName" th:value="${params.get('userName')}"/>
				姓名：<input name="userRealName" th:value="${params.get('userRealName')}"/>
				年龄：<input name="userAge" th:value="${params.get('userAge')}"/>
				<input type="submit" value="查询"/>
			</form>
		</div><br/>
		<div>
			<a href="toAdd" sec:authorize="hasAuthority('userinfo:add')">新增</a>
			<a href="javascript:void(0)" onclick="deletes()"  sec:authorize="hasAuthority('userinfo:delete')">批量删除</a>
		</div><br/>
		<table border="1px">
			<tr>
				<th><input type="checkbox" onclick="checkIds(this)"/></th>
				<th>主键id</th>
				<th>账号</th>
				<th sec:authorize="hasAuthority('userinfo:password')">密码</th>
				<th>姓名</th>
				<th>头像</th>
				<th>年龄</th>
				<th>操作</th>
			</tr>
			<tr th:each="user : ${datas }">
				<td><input type="checkbox" name="ids" th:value="${user.id }"/></td>
				<td>[[${user.id }]]</td>
				<td th:text="${user.userName}"></td>
				<td sec:authorize="hasAuthority('userinfo:password')">[[${user.userPassword }]]</td>
				<td>[[${user.userRealName }]]</td>
				<td><img th:src="@{${user.userHeadimg}}" /></td>
				<td>[[${user.userAge }]]</td>
				<td>
					<a th:href="${'toAdd?id=' + user.id}">修改</a>
					<a th:href="${'delete?ids=' + user.id}">删除</a>
				</td>
			</tr>
		</table><br/>
		<div class="pages">
			<a th:href="${'list?pageNum=' + (pageInfo.pageNum > 1 ? pageInfo.pageNum - 1 : 1)}">上一页</a>
			<a th:each="p : ${#numbers.sequence(1,pageInfo.pages)}" th:href="${'list?pageNum=' + p }">[[${{p }}]]</a>
			<a th:href="${'list?pageNum=' + (pageInfo.pageNum < pageInfo.pages ? pageInfo.pageNum + 1 : pageInfo.pages)}">下一页</a>
		</div>
	</div>
	<script type="text/javascript">

		function checkIds(e){
			$("input[name=ids]").each((index, dom) => {
				dom.checked = e.checked
			})
		}
		
		function deletes(){
			location.href = "delete?ids=" +  $("input[name=ids]:checked").map((index, dom) => {
				return dom.value;
			}).get().join(",");
		}
	</script>
</body>
</html>